package com.cxzl.pcxt.action.front;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;
import com.cxzl.pcxt.entity.AnswerDetail;
import com.cxzl.pcxt.entity.User;
import com.cxzl.pcxt.service.AnswerDetailService;
import com.cxzl.pcxt.service.PaperService;

@Controller("pcxtQuestionnaireAction")
@RequestMapping("pcxt/quest")
public class AnswerDetailAction {

	@Resource(name = "pcxtPaperService")
	private PaperService paperService;

	@Resource(name = "pcxtAnswerDetailService")
	private AnswerDetailService answerDetailService;

	@RequestMapping("quest.htm")
	public String list(ModelMap model) {
		return "pcxt/mobile/quest";
	}

	@RequestMapping("add.htm")
	public String add(String jsonStr, int paperId, ModelMap model,
			HttpServletRequest req) {
		// 判断用户是否登录
		User user = (User) req.getSession().getAttribute(User.USER_SESSION_ID);
		if (user == null) {
			return "redirect:/loginPage.htm";
		}

		List<AnswerDetail> list = JSON.parseArray(jsonStr, AnswerDetail.class);
		// answerDetailService.answerPaper(list);
		answerDetailService.answerPaper(list, user.getUserId(), paperId);
		return "pcxt/mobile/add";
	}
}
